<template>
	<view class="alarm-handle-bg">
		<view class="whole-width-bg">
			<view class="btn1-bg" @click="resumeStop">急停恢复</view>
		</view>
		<view class="whole-width-bg">
			<view class="btn1-bg" @click="continueTask">继续执行</view>
		</view>
		<view class="whole-width-bg">
			<view class="btn1-bg" @click="restartTask">重新执行</view>
		</view>
		<view class="whole-width-bg">
			<view class="btn1-bg" @click="stopMove">停止运动</view>
		</view>
		<view class="whole-width-bg">
			<view class="btn1-bg" @click="clearMove">移除运动</view>
		</view>
	</view>
</template>

<script>
	import robotApi from '../apis/robotApi';
	export default {
		name: "robot-alarm-handle",
		data() {
			return {

			};
		},
		methods: {
			resumeStop() {
				robotApi.resumeState({})
					.then(res => {
						console.log("急停恢复 成功：" + JSON.stringify(res))
						if (typeof(res.data) === 'boolean' && res.data && (res.code == 200 || res.code == "200")) {
							uni.showToast({
								title: res.msg?res.msg:"操作成功"
							})
						} else {
							uni.showToast({
								title: res.msg
							})
						}
					})
					.catch(error => {
						console.log("急停恢复 错误：" + JSON.stringify(error))
					})
			},
			
			continueTask() {
				robotApi.resumeState({})
					.then(res => {
						console.log("急停恢复 成功：" + JSON.stringify(res))
						if (typeof(res.data) === 'boolean' && res.data && (res.code == 200 || res.code == "200")) {
							this.continuWelding()
						} else {
							uni.showToast({
								title: res.msg
							})
						}
					})
					.catch(error => {
						console.log("急停恢复 错误：" + JSON.stringify(error))
					})
			},
			continuWelding() {
				robotApi.continuTask({})
					.then(res => {
						console.log("继续执行焊接 成功：" + JSON.stringify(res))
						if (typeof(res.data) === 'boolean' && res.data && (res.code == 200 || res.code == "200")) {
							uni.showToast({
								title: res.msg?res.msg:"操作成功"
							})
						} else {
							uni.showToast({
								title: res.msg
							})
						}
					})
					.catch(error => {
						console.log("继续执行焊接 错误：" + JSON.stringify(error))
					})
			},
			
			restartTask() {
				robotApi.resumeState({})
					.then(res => {
						console.log("急停恢复 成功：" + JSON.stringify(res))
						if (typeof(res.data) === 'boolean' && res.data && (res.code == 200 || res.code == "200")) {
							this.restartWelding()
						} else {
							uni.showToast({
								title: res.msg
							})
						}
					})
					.catch(error => {
						console.log("急停恢复 错误：" + JSON.stringify(error))
					})
			},
			restartWelding() {
				robotApi.reStartTask({})
					.then(res => {
						console.log("重新执行焊接 成功：" + JSON.stringify(res))
						if (typeof(res.data) === 'boolean' && res.data && (res.code == 200 || res.code == "200")) {
							uni.showToast({
								title: res.msg?res.msg:"操作成功"
							})
						} else {
							uni.showToast({
								title: res.msg
							})
						}
					})
					.catch(error => {
						console.log("重新执行焊接 错误：" + JSON.stringify(error))
					})
			},
			
			stopMove() {
				robotApi.stopCommond({})
					.then(res => {
						console.log("停止运动 成功：" + JSON.stringify(res))
						if (typeof(res.data) === 'boolean' && res.data && (res.code == 200 || res.code == "200")) {
							uni.showToast({
								title: res.msg?res.msg:"操作成功"
							})
						} else {
							uni.showToast({
								title: res.msg
							})
						}
					})
					.catch(error => {
						console.log("停止运动 错误：" + JSON.stringify(error))
					})

			},
			
			clearMove() {
				robotApi.clearCommond({})
					.then(res => {
						console.log("移除移动 成功：" + JSON.stringify(res))
						if (typeof(res.data) === 'boolean' && res.data && (res.code == 200 || res.code == "200")) {
							uni.showToast({
								title: res.msg?res.msg:"操作成功"
							})
						} else {
							uni.showToast({
								title: res.msg
							})
						}
					})
					.catch(error => {
						console.log("移除移动 错误：" + JSON.stringify(error))
					})

			},
		}
	}
</script>

<style scoped lang="scss">
	.alarm-handle-bg {
		padding: 40rpx;
	}

	.whole-width-bg {
		display: flex;
		align-items: center;
		width: 100%;
		margin-bottom: 30rpx;
	}

	.btn1-bg {
		padding: 20rpx 0;
		flex: 1;
		border-radius: 16rpx;
		background-color: #3b82f6;
		color: #FFFFFF;
		text-align: center;
	}

	.mar-left {
		margin-left: 20rpx;
	}

	.mar-right {
		margin-right: 20rpx;
	}

	.mar-top {
		margin-top: 30rpx;
	}

	.mar-bottom {
		margin-bottom: 30rpx;
	}
</style>